/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ecom.beans.menuorder;

import ecom.beans.customer.*;

import java.io.Serializable;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import java.util.*;
import javax.persistence.Temporal;

/**
 *
 * @author alina
 */
@Entity
public class MenuOrderEntity implements Serializable {
    private static final long serialVersionUID = 1L;


    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    
    private int type; //1 for instant order, 2 for later order
    private double orderTotalPrice;
    private String customerName;
    private String deliveryAddress;
    
   
    @Temporal(javax.persistence.TemporalType.DATE)
    private Date orderDate;
   
    //for an instant order, the desiredDeliveryDate and the orderDate are the same, differing
    //by a few minutes (deliveryTime)
    //for a later order (even today), the dates are the same but deliveryTime is more
    @Temporal(javax.persistence.TemporalType.DATE)
    private Date desiredDeliveryDate;
    
    //status = delivered or undelievered
    //delivered if desiredDeliveryDate < current date
    private String status;
    private int orderTotalSmiles;
    
    //estimated delivery time
    //if it's an instant order, it is a random value in minutes
    //if it's a long-term order, it is the difference between the desiredDeliveryDate and the orderDate
    private long deliveryTime;

    public String getDeliveryAddress() {
        return deliveryAddress;
    }

    public void setDeliveryAddress(String deliveryAddress) {
        this.deliveryAddress = deliveryAddress;
    }

    public String getCustomerName() {
        return customerName;
    }

    public void setCustomerName(String customerName) {
        this.customerName = customerName;
    }

    public double getDeliveryTime() {
        return deliveryTime;
    }

    public void setDeliveryTime(long deliveryTime) {
        this.deliveryTime = deliveryTime;
    }

    public Date getDesiredDeliveryDate() {
        return desiredDeliveryDate;
    }

    public void setDesiredDeliveryDate(Date desiredDeliveryDate) {
        this.desiredDeliveryDate = desiredDeliveryDate;
    }

    public Date getOrderDate() {
        return orderDate;
    }

    public void setOrderDate(Date orderDate) {
        this.orderDate = orderDate;
    }

    public double getOrderTotalPrice() {
        return orderTotalPrice;
    }

    public void setOrderTotalPrice(double orderTotalPrice) {
        this.orderTotalPrice = orderTotalPrice;
    }

    public int getOrderTotalSmiles() {
        return orderTotalSmiles;
    }

    public void setOrderTotalSmiles(int orderTotalSmiles) {
        this.orderTotalSmiles = orderTotalSmiles;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }
    
    //TODO
    //add another entity which contains the dishes that were ordered by the customer
    
    
    
    
  /*  
    @ManyToOne(cascade ={CascadeType.ALL})
    @JoinColumn(nullable=false)
    private CustomerEntity customer;*/

    public MenuOrderEntity() {
    }
    
    public MenuOrderEntity(Long customerId) {
        
        orderTotalPrice = 0.0;
        this.setId(customerId);
    }
    
    /*
    public MenuOrderEntity(CustomerEntity customer) {
        
        orderTotalPrice = 0.0;
        this.setCustomer(customer);
    }
    
    public CustomerEntity getCustomer() { 
        return customer; 
    }
   
    public void setCustomer(CustomerEntity customer) {
        this.customer = customer;
    } */
    
  
    public void setId(Long id) {
        this.id = id;
    }

    public Long getId() {
        return id;
    } 
    
    
    
   


    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof MenuOrderEntity)) {
            return false;
        }
        MenuOrderEntity other = (MenuOrderEntity) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "ejb.order.OrderEntity[id=" + id + "]";
    }

}